(function () {
    //     $("#btn-reservation").css('display','block');

    // Your code here...
    var nIntervId;
    var count = 1;
    var goDate;

    function go() {
        console.log("正在帮你抢购＊＊＊＊＊＊＊＊＊＊＊＊＊ 刷新" + count + "次");
        count++;
        // iPhone X go set time
        if (Date.now() >= new Date("2017-11-03 15:59:59")) {
            console.log("开始抢购" + Date.now());

            //商品抢购
            if ($("#choose-btn-ko").length == 1) {
                console.log("(++++++++++++ 抢购");
                var sku = window.location.pathname.replace(/[^0-9]/ig, "");
                var ref = "//cart.jd.com/gate.action?pid=" + sku + "&pcount=1&ptype=1";
                console.log("https:" + ref);
                //5089237
                $("#choose-btn-ko").attr("href", ref); //
                // parent.frames[0].document.getElementById("choose-btn-ko").click();
                document.getElementById("choose-btn-ko").click();
                return;
            }

            //预约抢购
            if ($("#btn-reservation").length == 1) {
                console.log("(++++++++++++正在预约抢购");

                $("#btn-reservation").click();
                return;
            }

            //秒杀
            // if ($("#InitCartUrl").length == 1) {
            //     console.log("(++++++++++++正在秒杀");
            //     //                 $("#InitCartUrl").click();

            //     window.location.href = $("#InitCartUrl").attr('href');
            //     return;
            // }

            //去购物车结算
            if ($("#GotoShoppingCart").length == 1) {
                console.log("(++++++++++++正在去购物车结算");
                window.location.href = $("#GotoShoppingCart").attr('href');
            }

            //去结算
            if ($(".submit-btn").length == 1) {
                console.log("(++++++++++++正在去结算");

                //只提交我抢购的商品
                //var sku = window.location.pathname.replace(/[^0-9]/ig, "");

                //$("#toggle-checkboxes_up").trigger("click");
                //全不选择
                //parent.frames[0].document.getElementById("toggle-checkboxes_up").click();

                //$('input:checkbox').attr("checked",false);
                //$("input:checkbox[value^='"+sku+"']").trigger("click");

                //$("input:checkbox[value^='"+sku+"']").attr("checked",true);

                //                 parent.frames[0].document.getElementsByClassName("submit-btn")[0].click();
                //                  $(".submit-btn")[0].click();
                //                 document.getElementsByClassName("submit-btn")[0].click();

                // 去结算：普通
                var binter = ($(this).attr('data-bind') == 2) ? true : false;
                gotoBalance(binter);
            }
            //提交订单order-submit
            if ($("#order-submit").length == 1) {
                console.log("(++++++++++++正在提交订单");
                //$(".payment-item item-selected online-payment")

                //在线支付
                //                 $("#order-submit").click();


                // submit_Order();

                window.location.href = 'https://order.jd.com/center/list.action';
            }
        }

        // window.location.reload();
    }

    if (window.location.hostname.indexOf("item.jd.com") >= 0) {
        //这里需要注意的是，prompt有两个参数，前面是提示的话，后面是当对话框出来后，在对话框里的默认值
        //         var d = prompt("请输入抢购开始时间", "2017-11-03 15:59:59");
        //         //如果返回的有内容
        //         if (d) {
        //             try {
        //                 goDate = new Date(d);
        //                 console.log("设定时间成功:" + goDate);

        //                 alert("监控期间,请保持标签页在最前面");
        // //                             go(); //0.25秒执行一次
        //                              nIntervId = setInterval(go, 250);
        //             }
        //             catch (e) {
        //                 console.log(e);
        //                 //alert("时间格式不正确,请使用yyyy-MM-dd hh:mm:ss格式,精确到秒, 请重试");
        //             }
        //         }
        //         else {
        //             alert("请抢购时间, 请重重试");

        //         }

        // nIntervId = setInterval(go, 50000);

        go();
    } else {
        go(); //0.25秒执行一次
    }


    /*
        clearInterval(nIntervId);//停止监控
        */

    //去结算
    function gotoBalance(binter) {
        var selected = $(".item-selected");
        if (selected && selected.length) {
            try {
                if (binter) {
                    if ($('#overseaSelectedCount').val() > 110) {
                        this.showAlertDlg('勾选的商品太多啦', '单次结算商品不超过110件，请重新选择结算商品');
                        return;
                    }
                } else {
                    if ($('#noOverseaSelectedCount').val() > 110) {
                        this.showAlertDlg('勾选的商品太多啦', '单次结算商品不超过110件，请重新选择结算商品');
                        return;
                    }
                }
                try {
                    if (binter) {
                        this.doLog('newcart', 'clickcart', 'gotoorderoversea3');
                    }
                    this.doLog('newcart', 'clickcart', $.jCookie("ipLoc-djd"));
                } catch (e) {}
                // 区分京东国际结算 和 京东结算
                // var orderInfoUrl = PurchaseAppConfig.Domain + "/gotoOrder.action" + (binter ? '?flowId=10&rd=' : '?rd=') + Math.random();
                var orderInfoUrl = "//cart.jd.com/gotoOrder.action" + (binter ? '?flowId=10&rd=' : '?rd=') + Math.random();
                if ($("#isLogin").val() == 0) {
                    $("#isLogin").val(0);
                    this.doLogin({
                        modal: true, // false跳转,true显示登录注册弹层
                        returnUrl: orderInfoUrl,
                        'clstag1': "login|keycount|5|5",
                        'clstag2': "login|keycount|5|6&sourcePage=noReg",
                        firstCheck: false,
                        complete: function () {
                            $("#isLogin").val(1);
                            window.location.href = orderInfoUrl;
                        }
                    });
                } else {
                    window.location.href = orderInfoUrl;
                }
            } catch (e) {
                window.location.href = orderInfoUrl;
            }
        } else {
            if ($('.cart-tiny-tips').length != 0) return;
            $('.submit-btn').after('<div class="cart-tiny-tips" style="width:160px;right:' + (this.t == "0" ? '-30' : '0') + 'px;top:-35px;"><i class="warn-ico"></i>请至少选择一件商品哟~</div>');
            setTimeout(function () {
                $('.cart-tiny-tips').remove();
            }, 1500);
        }
    }

    /**
     * 提交订单的方法
     */
    function submit_Order(enterPriseUser, agreement, jxj) {
        //港澳售项目
        var hongKongId = $("#hongKongId").val();
        var overSeasId = $("#overSeasId").val(); // 全球售ID
        var taiWanId = $("#taiWanId").val(); // 台湾ID
        var canSubmitFlag = false;
        var consignee_area = $("#hideAreaIds").val();
        if (consignee_area != null) {
            var consignee_provinceId = consignee_area.split("-")[0];
            if (consignee_provinceId == hongKongId || consignee_provinceId == overSeasId || consignee_provinceId == taiWanId) {
                //先判断是否有港澳无货标签，如果有港澳无货的，弹框：不支持配送返回购物车提示;再判断是否勾选了同意按钮，没勾选弹框：继续提交提示
                var j = $("body");
                var allGoodsCount = $(".goods-list .goods-item").length;
                var noStockCount = $(".hknostock").length;
                if (noStockCount > 0 && noStockCount == allGoodsCount) { // 港澳台、海外公用一个无货class
                    var a = $("#hkmt-box01").html();
                    j.dialog({
                        title: "\u63d0\u793a",
                        width: 420,
                        height: 125,
                        type: "html",
                        source: a
                    });
                } else {
                    if ((consignee_provinceId == hongKongId || consignee_provinceId == overSeasId || consignee_provinceId == taiWanId) && $("#overseamtbuy").is(":checked")) {
                        canSubmitFlag = true;
                    } else {
                        //弹框 继续提交提示
                        alert("请查阅并同意协议后继续下单");
                        return;
                    }
                }
            } else {
                canSubmitFlag = true;
            }
        } else {
            canSubmitFlag = true;
        }

        if ($("#forcedChoice-times").css("display") != 'none' && $("#car_shipment_item").hasClass("curr")) {
            doEdit311Time(3);
            return;
        }
        if ($("#saveParam_promiseDate").val() == "" && $("#forcedChoice").val() && $("#saveParam_promiseType").val() == 3) {
            var shipTypeId = $("#shipment_select_support").val();
            doEdit311Time(shipTypeId, 1);
            log('gz_ord', 'gz_proc', 19, 'forcedChoice'); //提交订单时弹出预约日历埋点
            return;
        }
        if ($("#gsd-new-times-wmr").css("display") != 'none' && $("#gsd_shipment_item").hasClass("curr")) {
            doEdit311Time(3, 1);
            return;
        }


        if (agreement == 1) {
            $("#car_Agreement_check").attr("checked", true);
        }

        if (!$("#car_Agreement_tips").hasClass("hide") && !$("#car_Agreement_check").is(":checked") && $("#car_shipment_item").hasClass("curr")) {
            car_Agreement(1);
            return;
        } else if (!$("#car_Agreement_tips").hasClass("hide") && $("#car_Agreement_check").is(":checked") && agreement == 1) {
            closeDialog();
        }

        if (canSubmitFlag) {
            
            // var actionUrl = OrderAppConfig.Domain + "/order/submitOrder.action";
            var actionUrl = "https://trade.jd.com/shopping/order/submitOrder.action";
            var checkcodeTxt = null;
            var checkCodeRid = null;
            var payPassword = null;
            var remark = null;
            var trackID = null;
            var mobileForPresale = null;
            var presalePayType = null;
            var param = "";
            // 检查如果存在没保存，则直接弹到锚点
            if (!$("#submit_check_info_message").is(":hidden")) {
                var anchor = $("#anchor_info").val();
                window.location.hash = anchor;
                return;
            }
            // 验证是否输入验证码
            if (!isEmpty($("#checkCodeDiv").html())) {
                checkcodeTxt = $("#checkcodeTxt").val();
                if (isEmpty(checkcodeTxt)) {
                    alert("请先填写验证码!");
                    return;
                }
            }
            // 验证码的随机码
            if (!isEmpty($("#checkCodeDiv").html())) {
                checkCodeRid = $("#checkcodeRid").val();
            }
            // 验证是否输入支付密码
            if (!$("#paypasswordPanel").is(":hidden")) {
                //短密码判断是否是6位
                if ($(".sixDigitPassword").val() != undefined && $(".sixDigitPassword").val().length != 6) {
                    $("#no-pwd-error").show();
                    return;
                }
                payPassword = $("#txt_paypassword").val();
                if (isEmpty(payPassword)) {
                    $("#no-pwd-error").show();
                    return;
                }
            }

            // 预售验证手机号
            if ($("#preSale").data('ispresale')) {
                if ($("#presaleStepPay").val() == "1") { // 全款支付
                    presalePayType = 1;
                } else if ($("#presaleStepPay").val() == "3") { // 定金支付
                    presalePayType = 2;
                } else if ($("#presaleStepPay").val() == "5") { // 定金支付
                    presalePayType = 2;
                } else if ($("#presaleStepPay").val() == "2" || $("#presaleStepPay").val() == "4") {
                    if ($("#AllPayRadio").attr("class") == "presale-payment-item item-selected") {
                        presalePayType = 1;
                    } else {
                        presalePayType = 2;
                    }
                }
                if (presalePayType == 2) { // 定金支付必须要手机号码
                    if (check_presaleMobile()) {
                        if ($("#presaleMobile input").size() > 0) {
                            mobileForPresale = $("#presaleMobile input").val();
                            if (mobileForPresale.indexOf("*") > -1) {
                                return false;
                            }
                        } else {
                            mobileForPresale = $("#userMobileByPresale").html();
                        }
                    } else {
                        alert("请您先输入有效的预售手机号");
                        return;
                    }
                }
                if (typeof ($("#presaleEarnest").prop("checked")) !== 'undefined' && $("#presaleEarnest").prop("checked") != true && $("#presaleStepPay").val() != "6") {
                    alert("请您同意交付定金");
                    return;
                }
            }

            /**
             * 电视搭售会员时，提示用户关注不能退货的条款，避免争议
             * 主流程：使用配送方式来识别
             * loc流程：使用商家id和标记位来区分
             */
            if (($(".is-video-loc-ship").length > 0 && $("#agreeNoRefundInMain").val() == "false") ||
                ($("#cartVenderIdStr").val() == "613991" && $("#agreeNoRefundInLoc").val() == "false")) {
                var a = $("#virtual-box01").html();
                $("body").dialog({
                    title: "\u63d0\u793a",
                    width: 400,
                    type: "html",
                    source: a
                })
                return;
            }

            if (!isEmpty(checkcodeTxt)) {
                param = param + "submitOrderParam.checkcodeTxt=" + checkcodeTxt;
            }
            param = param + "&overseaPurchaseCookies=" + $("#overseaPurchaseCookies").val();
            if (!isEmpty(checkCodeRid)) {
                param = param + "&submitOrderParam.checkCodeRid=" + checkCodeRid;
            }
            if (!isEmpty(payPassword)) {
                param = param + "&submitOrderParam.payPassword=" + encodeURIComponent(stringToHex(payPassword));
            }
            var domList = $('.shopping-list').find('.remarks-items');
            if (domList.length != 0) {
                var domList = $('.shopping-list').find('.remarks-items');
                var remarks = [];
                for (var i = 0; i < domList.length; i++) {
                    if ($(domList[i]).attr('vendor') != '0') {
                        var remark = {};
                        remark.venderId = $(domList[i]).attr('vendor');
                        remark.remark = $(domList[i]).find('textarea').val();
                        if (!is_order_remark_forbid($(domList[i]).find('textarea').val())) {
                            alert('订单备注中含有非法字符');
                            return;
                        }
                        remarks.push(remark);
                    }
                }
                param = param + "&vendorRemarks=" + JSON.stringify(remarks);
            }
            if (!isEmpty($("#sopNotPutInvoice").val())) {
                param = param + "&submitOrderParam.sopNotPutInvoice=" + $("#sopNotPutInvoice").val();
            } else {
                param = param + "&submitOrderParam.sopNotPutInvoice=" + false;
            }
            if (!isEmpty(mobileForPresale)) {
                param = param + "&submitOrderParam.presaleMobile=" + mobileForPresale;
            }
            if (null != presalePayType) {
                param = param + "&submitOrderParam.presalePayType=" + presalePayType;
            }
            if (isGiftBuy()) {
                var hidePrice = false;
                if (!$("#giftBuyHidePriceDiv").is(":hidden")) {
                    hidePrice = $("#giftBuyHidePrice").is(":checked");
                }
                param = param + "&submitOrderParam.giftBuyHidePrice=" + hidePrice;
            }
            trackID = $("#TrackID").val();
            if (!isEmpty(trackID)) {
                param = param + "&submitOrderParam.trackID=" + trackID;
            }
            var indexFlag = param.substring(0, 1);
            if (indexFlag == "&") {
                param = param.substring(1, param.length);
            }
            param = addFlowTypeParam(param);
            var regionId = $("#regionId").val();
            var shopId = $("#shopId").val();
            if (regionId) {
                param += "&regionId=" + regionId;
            }
            if (shopId) {
                param += "&shopId=" + shopId;
            }
            var easyBuyFlag = $("#easyBuyFlag").val();
            if (easyBuyFlag == "1" || easyBuyFlag == "2") {
                param += "&ebf=" + easyBuyFlag;
            }
            var ignorePriceChange = $('#ignorePriceChange').val();
            if (ignorePriceChange) {
                param += "&submitOrderParam.ignorePriceChange=" + ignorePriceChange;
            }
            var onlinepaytype = $(".payment-item.item-selected").attr('onlinepaytype');
            var paymentId = $(".payment-item.item-selected").attr('payid');
            try {
                log('ord', 'trade', '20', paymentId + onlinepaytype);
            } catch (e) {}
            if (onlinepaytype == "1") {
                var lastneedPay = $("#lastneedPay").val();
                var limit = $("#cod_bt").attr("limit");
                if (parseFloat(lastneedPay) > parseFloat(limit)) {
                    showSubmitErrorMessage("亲爱的用户您的白条剩余额度￥" + limit + "，请选择其他支付方式！");
                    return;
                }
                var baitiaoInfo = $("#baitiaoPayRequest").val();
                if (!isEmpty(baitiaoInfo)) {
                    param += "&" + baitiaoInfo;
                }
                //如果白条首次还款日期未自动设置（#baitiaoPayRequest中），则使用结算页初始化时的默认值。
                var baitiaoPayRepayDateInfo = $("#baitiaoPayRepayDateRequest").val();
                if (!isEmpty(baitiaoPayRepayDateInfo) && param.indexOf("repayDate") < 0) {
                    param += "&" + baitiaoPayRepayDateInfo;
                }
            }
            if ($(".payment-item[onlinepaytype=1]").length == 0 || $(".payment-item[onlinepaytype=1]").hasClass("payment-item-disabled")) {
                param += "&submitOrderParam.btSupport=0";
            } else {
                param += "&submitOrderParam.btSupport=1";
            }
            if (onlinepaytype == "3") {
                var card = $("#" + $("#jdpy_cardInfo").val());
                var cardInfo = card.attr("cardInfo");
                var cardkey = card.attr("key");
                if (!isEmpty(cardInfo)) {
                    param += "&submitOrderParam.cardInfo=" + cardInfo;
                }
                if (!isEmpty(cardkey)) {
                    param += "&submitOrderParam.cardkey=" + cardkey;
                }
                param += "&submitOrderParam.cardsign=" + card.attr("sign");
                param += "&submitOrderParam.cardvalid=" + card.attr("valid");
                param += "&submitOrderParam.cardid=" + card.attr("id");
            }
            var presaleSelectType;
            if ($(".presale-payment-item").hasClass("item-selected")) {
                presaleSelectType = $(".presale-payment-item.item-selected").attr("selectType");
            }
            if (presaleSelectType != null) {
                param += "&submitOrderParam.payType4YuShou=" + presaleSelectType;
            }
            var eid = $('#eid').val();
            if (eid) {
                param += "&submitOrderParam.eid=" + eid;
            }
            var fp = $('#fp').val();
            if (fp) {
                param += "&submitOrderParam.fp=" + fp;
            }

            var riskControl = $('#riskControl').val();
            if (riskControl) {
                param += "&riskControl=" + riskControl;
            }

            var isBestCoupon = $('#isBestCoupon').val();
            if (isBestCoupon) {
                param += "&submitOrderParam.isBestCoupon=" + isBestCoupon;
            }
            if (jxj != 1 && $("#skuDetailInfo").attr("notOneMainsku") == "true" && $('.payment-item.item-selected').attr('payId') == 4) {
                //惊喜金
                var skuDetailInfo = $("#skuDetailInfo").html().replace('&', '');
                param += "&submitOrderParam.skuDetailInfo=" + skuDetailInfo;
                param += "&submitOrderParam.amount=" + $("#sumPayPriceId").html().replace("￥", "");
                param += "&submitOrderParam.needCheck=" + 1;
            } else {
                param += "&submitOrderParam.jxj=1"
            }
            //风控埋点
            var downRisktak = $("#downRisktak").val();
            //是否降级
            if (downRisktak == "0") {
                try {
                    var track_id = getTakId();
                    if (track_id != null && track_id != "") {
                        param += "&submitOrderParam.trackId=" + track_id;
                    }
                } catch (e) {}
            }


            var submitButtonABTest = $('#submitButtonABTest').val();
            if (submitButtonABTest && submitButtonABTest == 1) {
                log('ord_abtest', 'trade_abtest', $('#order-submit').data('data-clkwl'));
            }
            // 提交loading
            $('body').append("<div id='submit_loading' class='purchase-loading'><div class='loading-cont'></div></div>");

            jQuery.ajax({
                type: "POST",
                dataType: "json",
                url: actionUrl,
                data: param,
                cache: false,
                success: function (result) {
                    console.log(result);
                    // 没有登录跳登录
                    if (isUserNotLogin(result)) {
                        goToLogin();
                        return;
                    }
                    if (result.hasJxj) {
                        var ycDialog = $('body').dialog({
                            title: null,
                            width: 420,
                            height: 230,
                            type: 'html',
                            source: $('#jxj-confirm-dialog').html(),
                            onReady: function () {
                                $("#submit_loading").remove();
                                $('.jxj-confirm-box a.btn-9').click(function () {
                                    submit_Order(enterPriseUser, agreement, 1);
                                });
                            }
                        });
                        return;
                    }
                    $('#ignorePriceChange').val(0);
                    if (result.success) {
                        // 企业用户合并支付
                        if (enterPriseUser == 1) {
                            successUrl = OrderAppConfig.Protocol + "order.jd.com/center/list.action";
                            // 等待拆单，定时450毫秒
                            window.setTimeout('window.location.href=successUrl+"?rd="+Math.random();', 450);
                            return;
                        }
                        // 跳订单中心列表
                        if (result.payInfo) {
                            $('#direct_pay input[name=orderId]').val(result.payInfo.orderId);
                            $('#direct_pay input[name=orderType]').val(result.payInfo.orderType);
                            $('#direct_pay input[name=toType]').val(result.payInfo.toType);
                            $('#direct_pay input[name=directPayInfoJson]').val(result.payInfo.directPayInfoJson);
                            $('#direct_pay input[name=payMethod]').val(result.payInfo.payMethod);
                            $('#direct_pay input[name=key]').val(result.payInfo.key);
                            $('#direct_pay input[name=countdownTime]').val(result.payInfo.countdownTime);
                            $('#direct_pay input[name=orderSubmitTime]').val(result.payInfo.orderSubmitTime);
                            window.setTimeout("$('#direct_pay').submit();", 450);

                            return;
                        }
                        // 全球售
                        if (result.overSea) {
                            var payUrlForOverSeas = OrderAppConfig.Protocol + "pcashier.jd.com/cashier/index.action?";
                            var orderIdForOverSeas = result.orderId;
                            var reqInfoForOverSeas = result.reqInfo;
                            var signForOverSeas = result.sign;
                            realUrl = payUrlForOverSeas + "orderId=" + orderIdForOverSeas + "&reqInfo=" + reqInfoForOverSeas + "&sign=" + signForOverSeas;
                            window.setTimeout('window.location.href=realUrl;', 450);
                            return;
                        }
                        if (result.goJumpOrderCenter) {
                            successUrl = OrderAppConfig.Protocol + "order.jd.com/center/list.action";
                            // 等待拆单，定时450毫秒
                            window.setTimeout('window.location.href=successUrl+"?rd="+Math.random();', 450);
                            return;

                        } else {
                            successUrl = "//success.jd.com/success/success.action";
                            window.location.href = successUrl + "?orderId=" + result.orderId + "&rid=" + Math.random();
                            return;
                        }

                    } else {
                        if (result.message != null) {
                            //价格提高
                            if (result.resultCode == 600160) {
                                $("#submit_loading").remove();
                                showPriceIncreaseDialog(result.message);
                            } else if (result.message.indexOf("支付密码不正确") != -1) {
                                $("#submit_loading").remove();
                                $("#pwd-error .error-msg").text(result.message);
                                $("#pwd-error").show();
                                if ($(".sixDigitPassword").val() != undefined && $(".sixDigitPassword").val().length > 0) {
                                    resetPaypassword();
                                }
                                $("#txt_paypassword").val("");
                                return;
                            } else if (result.message.indexOf("商品无货") != -1 && !isLocBuy()
                                //no homeservice
                                ||
                                (null !== result.noSupportHomeServiceSkuList && 'null' !== result.noSupportHomeServiceSkuList)) {
                                $("#submit_loading").remove();
                                var outSkus = result.noStockSkuIds;
                                var resultCode = result.resultCode;
                                if (resultCode == '600182' && null != result.noSupportHomeServiceSkuList) {
                                    outSkus = outSkus == null ? (result.noSupportHomeServiceSkuList).toString() : (outSkus + ',' + (result.noSupportHomeServiceSkuList).toString());
                                }
                                // 对无货商品的处理
                                showSubmitErrorMessage(result.message);
                                if (!isEmpty(outSkus)) {
                                    if (isLipinkaPhysical() || isCarO2OFlow()) {
                                        return;
                                    }
                                    var flowType = $("#flowType").val();
                                    if ((flowType == "" || flowType == 10) && resultCode != 600159) {
                                        doOutSku(outSkus, resultCode, result.addressVO);
                                    } else {
                                        window.location.href = cartUrl + '?outSkus=' + outSkus + '&rid=' + Math.random();
                                        return;
                                    }
                                }
                            } else if (result.message.indexOf("收货人信息中的省市县选择有误") != -1) {
                                var consigneeId = $("#consignee_id").val();
                                //consigneeList(consigneeId);
                                $("#submit_loading").remove();
                                showSubmitErrorMessage("亲爱的用户，由于地址已经升级，请重新选择！");
                            } else if (result.message.indexOf("由于订单金额较大") != -1) {
                                $("#submit_loading").remove();
                                showSubmitErrorMessage(result.message);
                                return;
                            } else if (result.message.indexOf("验证码不正确") != -1) {
                                $("#submit_loading").remove();
                                showSubmitErrorMessage(result.message);
                                getNextCheckCode(); // 刷新验证码
                                return;
                            } else if (result.message.indexOf("正在参与预售活动") != -1) {
                                var a = result.message.indexOf("您购买的商品");
                                var b = result.message.indexOf("正在参与预售活动");
                                var outSkus = result.message.substring(a + 6, b);
                                if (!isEmpty(outSkus)) {
                                    var tmpHtml = "";
                                    var skuList = outSkus.split(",");
                                    for (var i = 0; i < skuList.length; i++) {
                                        tmpHtml = tmpHtml + "<a target=\"_parent\" href=\"http://item.jd.com/" + skuList[i] + ".html\">" + skuList[i] + "</a>,";
                                    }
                                    tmpHtml = tmpHtml.substring(0, tmpHtml.length - 1);
                                    result.message = "您购买的商品" + tmpHtml + "正在参与预售活动,请进入商品详情页单独购买";
                                }
                                $("#submit_loading").remove();
                                showSubmitErrorMessage(result.message);
                            } else if (result.scaleSkuInfoListVO != null && result.scaleSkuInfoListVO.length > 0) { //抢购限制
                                $("#submit_loading").remove();
                                showScaleBuyDialog(result);
                                return;
                            } else if (result.resultCode == 600171) {
                                $("#submit_loading").remove();
                                showSamMemberDialog(result.message);
                            } else if (result.purchaseSkuInfoListVO != null && result.purchaseSkuInfoListVO.length > 0) {
                                //限购
                                $("#submit_loading").remove();
                                showPurchaseList(result.purchaseSkuInfoListVO, '抱歉，以下商品为限购商品，请返回购物车修改 ')
                            } else if (result.resultCode == 600201) {
                                //TODO
                                $("#submit_loading").remove();
                                param += "&submitOrderParam.msgUuid=" + result.msgUuid;
                                var a = template('J_common-risk-control-dialog', {
                                    'mobile': result.msgMobile,
                                    'param': param
                                });
                                $("body").dialog({
                                    title: null,
                                    width: 520,
                                    type: "html",
                                    extendMainClass: "common-tips-dialog",
                                    source: a,
                                    onReady: function () {
                                        window.orderApi.unDelegateEvent();
                                        window.orderApi.delegateEvent();
                                    }

                                });
                            } else {
                                $("#submit_loading").remove();
                                showSubmitErrorMessage(result.message);
                                return;
                            }
                        } else {
                            $("#submit_loading").remove();
                            showSubmitErrorMessage("亲爱的用户请不要频繁点击, 请稍后重试...");
                            return;
                        }
                    }
                },
                error: function (error) {
                    $("#submit_loading").remove();
                    $('#ignorePriceChange').val(0);
                    showSubmitErrorMessage("亲爱的用户请不要频繁点击, 请稍后重试...");
                }
            });
        }
    }

    function addFlowTypeParam(params) {
        var flowType = $("#flowType").val();
        if (isEmpty(flowType)) {
            return params;
        } else if ($("#flowType").val() === "15") {
            params = isEmpty(params) ? "flowType=" + flowType : params + "&flowType=" + flowType;
            if ($('#EarnestPayRadio').hasClass('item-selected')) {
                return params + '&preSalePaymentTypeInOptional=2'
            } else if ($('#AllPayRadio').hasClass('item-selected')) {
                return params + '&preSalePaymentTypeInOptional=1'
            }
            return params
        } else {
            if (isEmpty(params)) {
                return "flowType=" + flowType;
            } else {
                return params + "&flowType=" + flowType;
            }
        }
    }

    /**
     * 是否是礼品购流程
     */
    function isGiftBuy() {
        var giftBuyVal = $("#flowType").val();
        if (giftBuyVal == "2") {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 判断用户是否登录【此方法别动】
     */
    function isUserNotLogin(data) {
        if (data.error == "NotLogin") {
            return true;
        } else {
            try {
                var obj = eval("(" + data + ")");
                if (obj != null && obj.error != null && obj.error == "NotLogin") {
                    return true;
                }
            } catch (e) {}
        }
        return false;
    }

    /**
 * 判断是否是空
 * @param value
 */
function isEmpty(value){
	if(value == null || value == "" || value == "undefined" || value == undefined || value == "null"){
		return true;
	}
	else{
		value = value.replace(/\s/g,"");
		if(value == ""){
			return true;
		}
		return false;
	}
}

})();